/*
 *  Copyright 2019-2020 Zheng Jie
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.fzhucc.modules.sciPersonnelInfo.controller;

import com.fzhucc.annotation.AnonymousAccess;
import com.fzhucc.annotation.Log;
import com.fzhucc.modules.activity.domain.dto.ActivityDto;
import com.fzhucc.modules.sciPersonnelInfo.domain.SciPersonnelInfo;
import com.fzhucc.modules.sciPersonnelInfo.domain.dto.*;
import com.fzhucc.modules.sciPersonnelInfo.service.SciPersonnelInfoService;
import com.fzhucc.modules.sciTechnologyDemand.domain.dto.AllowSciTechnologyDemandDto;
import com.fzhucc.modules.sciTechnologyDemand.domain.dto.AuditSciTechnologyDemandDto;
import com.fzhucc.modules.sciTechnologyDemand.domain.dto.SciTechnologyDemandAddDto;
import com.fzhucc.modules.sciTechnologyDemand.domain.dto.SciTechnologyDemandQueryCriteria;
import com.fzhucc.utils.DesTool;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;

import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
 * @author yyg
 * @date 2023-11-30
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "劳模:管理")
@RequestMapping("/api/sciPersonnelInfo")
public class SciPersonnelInfoController {

    private final SciPersonnelInfoService sciPersonnelInfoService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('sciPersonnelInfo:list')")
    public void exportSciPersonnelInfo(HttpServletResponse response, SciPersonnelInfoQueryCriteria criteria) throws IOException {
        sciPersonnelInfoService.download(sciPersonnelInfoService.queryAll(criteria), response);
    }

    @Log("我的导出数据")
    @ApiOperation("我的导出数据")
    @GetMapping(value = "/my/download")
    @PreAuthorize("@el.check('sciPersonnelInfo:list')")
    public void myexportSciPersonnelInfo(HttpServletResponse response, SciPersonnelInfoQueryCriteria criteria) throws IOException {
        sciPersonnelInfoService.download(sciPersonnelInfoService.queryAllmy(criteria), response);
    }

    @GetMapping
    @Log("查询大赛“劳模工匠助企行”人才信息表")
    @ApiOperation("查询大赛“劳模工匠助企行”人才信息表")
    @PreAuthorize("@el.check('sciPersonnelInfo:list')")
    public ResponseEntity<Object> querySciPersonnelInfo(SciPersonnelInfoQueryCriteria criteria, Pageable pageable) {
        return new ResponseEntity<>(sciPersonnelInfoService.queryAll(criteria, pageable), HttpStatus.OK);
    }

    @AnonymousAccess
    @GetMapping(value = "/queryModel")
    @Log("开放查询劳模")
    @ApiOperation("开放查询劳模")
    public ResponseEntity<Object> queryModel() {
        return new ResponseEntity<>(sciPersonnelInfoService.queryModel(), HttpStatus.OK);
    }

    @AnonymousAccess
    @GetMapping(value = "/queryModelPage")
    @Log("开放查询劳模分页")
    @ApiOperation("开放查询劳模分页")
    public ResponseEntity<Object> queryModelPage(SciPersonnelInfoQueryCriteria criteria, Pageable pageable) {
        return new ResponseEntity<>(sciPersonnelInfoService.queryModelPage(criteria, pageable), HttpStatus.OK);
    }

    @GetMapping(value = "/my")
    @Log("我的大赛“劳模工匠助企行”人才信息表")
    @ApiOperation("我的大赛“劳模工匠助企行”人才信息表")
    //@PreAuthorize("@el.check('sciPersonnelInfo:list')")
    public ResponseEntity<Object> my(SciPersonnelInfoQueryCriteria criteria, Pageable pageable) {
        return new ResponseEntity<>(sciPersonnelInfoService.my(criteria, pageable), HttpStatus.OK);
    }

    @AnonymousAccess
    @GetMapping(value = "/list")
    @Log("h5、小程序查询大赛“劳模工匠助企行”人才信息表")
    @ApiOperation("h5、小程序查询大赛“劳模工匠助企行”人才信息表")
    public ResponseEntity<Object> list(SciPersonnelInfoQueryCriteria criteria, Pageable pageable) {
        criteria.setIsShow(1);
        return new ResponseEntity<>(sciPersonnelInfoService.queryAllh5(criteria, pageable), HttpStatus.OK);
    }

    @PutMapping(value = "/isAllowEdit")
    @Log("是否允许编辑")
    @ApiOperation("是否允许编辑")
    public ResponseEntity<Object> isAllowEdit(@Validated @RequestBody AllowSciPersonnelInfoDto dto) {
        sciPersonnelInfoService.isAllowEdit(dto);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @PostMapping
    @Log("新增大赛“劳模工匠助企行”人才信息表")
    @ApiOperation("新增大赛“劳模工匠助企行”人才信息表")
    @PreAuthorize("@el.check('sciPersonnelInfo:add')")
    public ResponseEntity<Object> createSciPersonnelInfo(@Validated @RequestBody SciPersonnelInfoAddDto dto) {
        return new ResponseEntity<>(sciPersonnelInfoService.create(dto), HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改大赛“劳模工匠助企行”人才信息表")
    @ApiOperation("修改大赛“劳模工匠助企行”人才信息表")
    @PreAuthorize("@el.check('sciPersonnelInfo:edit')")
    public ResponseEntity<Object> updateSciPersonnelInfo(@Validated @RequestBody SciPersonnelInfoEditDto dto) {
        sciPersonnelInfoService.update(dto);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除大赛“劳模工匠助企行”人才信息表")
    @ApiOperation("删除大赛“劳模工匠助企行”人才信息表")
    @PreAuthorize("@el.check('sciPersonnelInfo:del')")
    public ResponseEntity<Object> deleteSciPersonnelInfo(@RequestBody Integer[] ids) {
        sciPersonnelInfoService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @PutMapping(value = "/audit")
    @Log("大赛“劳模工匠助企行”人才信息表状态审核")
    @ApiOperation("大赛“劳模工匠助企行”人才信息表状态审核")
    public ResponseEntity<Object> auditSciPersonnelInfo(@Validated @RequestBody AuditSciPersonnelInfoDto dto) {
        sciPersonnelInfoService.auditSciPersonnelInfo(dto);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @GetMapping(value = "/getZqxCompanyArea")
    @Log("获取字典zqx_company_area 助企行企业技术需求征集表企业所在区域")
    @ApiOperation("获取字典zqx_company_area 助企行企业技术需求征集表企业所在区域")
    @AnonymousAccess
    public ResponseEntity<Object> getzqxCompanyArea() {
        return new ResponseEntity<>(sciPersonnelInfoService.getzqxCompanyArea(), HttpStatus.OK);
    }

    @GetMapping(value = "/getZqxMaType")
    @Log("获取字典zqx_ma_type 助企行企业技术需求征集表劳模工匠人才类型")
    @ApiOperation("获取字典zqx_ma_type 助企行企业技术需求征集表劳模工匠人才类型")
    @AnonymousAccess
    public ResponseEntity<Object> getZqxMaType() {
        return new ResponseEntity<>(sciPersonnelInfoService.getZqxMaType(), HttpStatus.OK);
    }

    @GetMapping(value = "/getZqxTechnology")
    @Log("获取字典zqx_technology 助企行企业技术需求征集表所需技术领域")
    @ApiOperation("获取字典zqx_technology 助企行企业技术需求征集表所需技术领域")
    @AnonymousAccess
    public ResponseEntity<Object> getZqxTechnology() {
        return new ResponseEntity<>(sciPersonnelInfoService.getZqxTechnology(), HttpStatus.OK);
    }

    @GetMapping(value = "/getZqxReType")
    @Log("获取字典zqx_re_type 助企行企业技术需求征集表需求类别")
    @ApiOperation("获取字典zqx_re_type 助企行企业技术需求征集表需求类别")
    @AnonymousAccess
    public ResponseEntity<Object> getZqxReType() {
        return new ResponseEntity<>(sciPersonnelInfoService.getZqxReType(), HttpStatus.OK);
    }


    @PostMapping(value = "/addWithSaveSci")
    @Log("小程序、h5新增劳模工匠信息表")
    @ApiOperation("小程序、h5新增劳模工匠信息表")
    public ResponseEntity<Object> createAll(@Validated @RequestBody SciPersonnelInfoAddDto dto) {
        return new ResponseEntity<>(sciPersonnelInfoService.createAll(dto), HttpStatus.CREATED);
    }

    /*@PostMapping(value = "/addWithSaveSciDraft")
    @Log("新增草稿")
    @ApiOperation("新增草稿")
    @PreAuthorize("@el.check('sciPersonnelInfo:add')")
    public ResponseEntity<Object> addWithSaveSciDraft(@Validated @RequestBody SciPersonnelInfoAddDto dto) {
        return new ResponseEntity<>(sciPersonnelInfoService.addWithSaveSciDraft(dto), HttpStatus.CREATED);
    }*/


    @AnonymousAccess
    @GetMapping("/{id}")
    @Log("查询单个劳模工匠信息表")
    @ApiOperation("查询单个劳模工匠信息表")
    public SciPersonnelInfoDto queryInfoById(@PathVariable Integer id) {
        return sciPersonnelInfoService.findById(id);
    }

    @GetMapping(value = "/getKeywordsListType")
    @Log("获取字典keywords_list")
    @ApiOperation("获取字典keywords_list")
    @AnonymousAccess
    public ResponseEntity<Object> getKeywordsListType() {
        return new ResponseEntity<>(sciPersonnelInfoService.getKeywordsListType(), HttpStatus.OK);
    }

    /*@GetMapping(value = "/getZnToken")
    @Log("获取智能token")
    @ApiOperation("获取智能token")
    @AnonymousAccess
    public ResponseEntity<Object> getZnToken(){
        return new ResponseEntity<>(sciPersonnelInfoService.getZnToken(), HttpStatus.OK);
    }*/

    @GetMapping(value = "/getZnTest")
    @Log("获取智能对接没发送")
    @ApiOperation("获取智能对接没发送")
    @AnonymousAccess
    public ResponseEntity<Object> getZnTest() throws Exception {
        return new ResponseEntity<>(sciPersonnelInfoService.getModelListTOSendJson1(), HttpStatus.OK);
    }

    @GetMapping(value = "/getZnTest2")
    @Log("获取智能对接没发送2")
    @ApiOperation("获取智能对接没发送2")
    @AnonymousAccess
    public ResponseEntity<Object> getZnTest2() throws Exception {
        return new ResponseEntity<>(sciPersonnelInfoService.getModelZDTOSendJson1(), HttpStatus.OK);
    }


    @GetMapping(value = "/getZnTestSend")
    @Log("获取智能对接发送出去")
    @ApiOperation("获取智能对接发送出去")
    @AnonymousAccess
    public ResponseEntity<Object> getZnTestSend() throws Exception {
        String s2 = sciPersonnelInfoService.getModelListTOSendJson();
        String key = "_18eZ2frJX";
        String result = DesTool.decryptString(s2, key);
        return new ResponseEntity<>(result, HttpStatus.OK);
    }

    @GetMapping(value = "/getZnTest2Send")
    @Log("获取智能对接发送出去2")
    @ApiOperation("获取智能对接发送出去2")
    @AnonymousAccess
    public ResponseEntity<Object> getZnTest2Send() throws Exception {
        String s2 = sciPersonnelInfoService.getModelZDTOSendJson();
        String key = "_18eZ2frJX";
        String result = DesTool.decryptString(s2, key);
        return new ResponseEntity<>(result, HttpStatus.OK);
    }


    @GetMapping(value = "/getZnTest2SendSingle")
    @Log("获取智能对接发送出去2单条记录的发")
    @ApiOperation("获取智能对接发送出去2单条记录的发")
    @AnonymousAccess
    public ResponseEntity<Object> getZnTest2SendSingle() throws Exception {
        return new ResponseEntity<>(sciPersonnelInfoService.getZnTest2SendSingle(), HttpStatus.OK);
    }

    @GetMapping(value = "/getZnTestSendSingle")
    @Log("获取智能对接发送出去单条记录的发")
    @ApiOperation("获取智能对接发送出去单条记录的发")
    @AnonymousAccess
    public ResponseEntity<Object> getZnTestSendSingle() throws Exception {
        return new ResponseEntity<>(sciPersonnelInfoService.getZnTestSendSingle(), HttpStatus.OK);
    }


    @GetMapping(value = "/sendDjModel")
    @Log("一次性推送劳模数据")
    @ApiOperation("一次性推送劳模数据")
    @AnonymousAccess
    public ResponseEntity<Object> sendDjModel() throws Exception {
        return new ResponseEntity<>(sciPersonnelInfoService.allgetZnTestSendSingle(), HttpStatus.OK);
    }

    @GetMapping(value = "/sendDjModelRetype")
    @Log("一次性推送劳模技术领域数据")
    @ApiOperation("一次性推送劳模技术领域数据")
    @AnonymousAccess
    public ResponseEntity<Object> sendDjModelRetype() throws Exception {
        return new ResponseEntity<>(sciPersonnelInfoService.sendDjModelRetype(), HttpStatus.OK);
    }

    @AnonymousAccess
    @GetMapping(value = "/bindZqxQyId")
    @Log("劳模根据企业表，同名绑定其id至劳模表")
    @ApiOperation("劳模根据企业表，同名绑定其id至劳模表")
    public ResponseEntity<Object> bindZqxQyId() {
        sciPersonnelInfoService.bindZqxQyId();
        return new ResponseEntity<>(HttpStatus.OK);
    }

}